<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/8/6
 * Time: 13:29
 */

namespace App\Http\Middleware;

use App\Models\Worker;
use Closure;
class CheckWorkerLogin
{

    public function handle($request, Closure $next)
    {
        if (!(request('aid') && request('sid') && (request('wid') || request('worker_id')))) {
            return error('未授权访问');
        }
        $wid = request('wid') ? request('wid') : request('worker_id');
        $worker = new Worker();
        $info = $worker->_redisGetOneByWid($wid);
        if (!$info) {
            return error('未授权访问');
        }
        if (!$info['status']) {
            return error('当前账号已被禁用');
        }
        $GLOBALS['shop_id'] = request('sid', 0);
        $GLOBALS['wid'] = request('wid');
        $GLOBALS['admin_id'] = request('aid');
        request('mid') &&  $GLOBALS['mid'] = request('mid');
        return $next($request);
    }

}

